package com.clive.ttwebdemo.service;

import com.clive.ttwebdemo.bean.DishesCategory;
import com.clive.ttwebdemo.exception.GlobalException;
import com.clive.ttwebdemo.mapper.DishCategoryMapper;
import com.clive.ttwebdemo.mapper.DishMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.List;
@Service
public class DishServiceCategoryImpl implements DishServiceCategory{
    @Autowired
    private DishCategoryMapper categoryMapper;
    @Autowired
    private DishMapper dishMapper;
    @Override
    public List<DishesCategory> findDishCategoryAll() {
        List<DishesCategory> List = categoryMapper.findDishCategoryAll();
        return List;
    }
    @Transactional
    @Override
    public int deleteDishesCategory(Integer id) {
        /**
         * 1.先删除菜品
         * 2.删除菜品分类
         */
         int i = dishMapper.deleteDishByCategoryId(id);
         int j = categoryMapper.deleteDishCategory(id);
         if(j<=0){
            throw new GlobalException("删除菜品分类失败");
         }
        return j;
    }
}
